<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>积分商城商品兑换记录</title>
    <script src="../commonCss.js"></script>
    <script src="../commonJs.js"></script>
    <link rel="stylesheet" href="../../css/common.css">
</head>

<body class="hold-transition skin-blue sidebar-mini">
<section class="content-header">
    <div class="ctc_title">积分商城商品兑换记录</div>
    <div class="down_line"></div>
</section>

<!-- Main content -->
<section class="content" >
    <div class="row">
        <div class="col-xs-12">
            <div class="box-header">
                <form class="form-inline">
                    <div class="form-group">
                        <label>查询：</label>
                        <select id="flag" class="form-control" style="text-align: center;font-size: 12px ;width:110px;">
                            <option value="">全部</option>
                            <option value="0">未发放</option>
                            <option value="1">已发放</option>
                        </select>&nbsp;&nbsp;
                        <input style="width: 260px;" class="form-control" type="text" id="searchKey"  placeholder="输入订单号/商品名称/用户姓名搜索"/>
                    </div>
                    <div class="form-group">
                        <button type="button"  onclick="getData()"  class="btn btn-block btn-primary">搜索</button>
                    </div>

                </form>
            </div>

            <div class="box-body" style="height:100%;">
                <table id="dataList" class="table table-bordered table-hover">
                    <thead>
                        <tr>
                            <th>订单号</th>
                            <th>用户姓名</th>
                            <th>手机号</th>
                            <th>商品名</th>
                            <th>积分</th>
                            <th>红包金额</th>
                            <th>支付金额</th>
                            <th>数量</th>
							<th>充值手机号</th>
                            <th>发放备注</th>
                            <th>状态</th>
                            <!--<th>兑换时间</th>-->
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody >
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</section>

<!-- 【发放商品】弹出窗内容 -->
<div class="modal" id="editPanel" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true" data-backdrop="static">
    <div class="modal-dialog" style="width: 50%;height: 40%;">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">
                    <span aria-hidden="true">×</span>
                    <span class="sr-only">Close</span>
                </button>
                <h4 class="modal-title" align="center" id="mopTitle"></h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" onsubmit="return false" id="form">
                    <fieldset  style="margin-top:2%;">
                        <input type="hidden" id="id" name="id">
						<input type="hidden" id="uid" name="uid">
                        <div class="form-group" >
                            <label class="col-md-2 control-label" style="color: red;">发放信息</label>
                            <div class="col-md-10">
                                <textarea class="form-control" rows="8" cols="6" name="content" id="content" placeholder="话费充值信息、京东卡密、物流单号信息填写"></textarea>
                            </div>
                        </div>

                    </fieldset>
                </form>
            </div>
            <div class="modal-footer" style="text-align: center">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary" onclick="confirmEditConfig();">确认发放</button>
            </div>
        </div>
    </div>
</div>

<!-- 【查看收货信息】弹出窗内容 -->
<div class="modal" id="receivePanel" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true" >
    <div class="modal-dialog" style="width: 50%;height: 40%;">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">
                    <span aria-hidden="true">×</span>
                    <span class="sr-only">Close</span>
                </button>
                <h4 class="modal-title" align="center" id="mopTitlelo"></h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" onsubmit="return false">
                    <fieldset  style="margin-top:2%;">
                        <div class="form-group" >
                            <label class="col-md-2 control-label" >收货人</label>
                            <div class="col-md-10">
                                <span style="text-align:left" class="col-md-10 control-label" id="receiver"></span>
                            </div>
                        </div>
                        <div class="form-group" >
                            <label class="col-md-2 control-label" >收货电话</label>
                            <div class="col-md-10">
                                <span style="text-align:left" class="col-md-10 control-label" id="phone"></span>
                            </div>
                        </div>
                        <div class="form-group" >
                            <label class="col-md-2 control-label" >收货地址</label>
                            <div class="col-md-10">
                                <span style="text-align:left" class="col-md-10 control-label" id="address"></span>
                            </div>
                        </div>

                    </fieldset>
                </form>
            </div>
        </div>
    </div>
</div>
<!-- page script -->
<script>
    $(document).ready(function() {
        //加载数据
        getData();

    });

    // 加载数据
    function getData(){
        var table = $('#dataList').DataTable({
            "destroy": true,   //可以重新初始化，用于搜索
            "lengthChange": false,
            "ordering": false,   //排序
            "info": true,		   //
            "autoWidth": false,   //宽度自动
            "paging": true,      //分页
            "searching": false,  //全局搜索关闭
            "processing": true,  //开启显示‘正在加载.../processing’
            "serverSide":true,    //true代表后台处理分页，false代表前台处理分页
            "bPaginate": false, //开关，是否显示分页器
            "bLengthChange": false, //开关，是否显示每页显示多少条数据的下拉框
            "ajax" :  {
                url:"/point/getMallRecordList",
                type:"POST",
                data:{
                     key : $("#searchKey").val(),
                     flag : $("#flag").val()
                }
            },
            //参数显示
            "columns": [
                {"data": "orderNo", 'sClass': "text-center",'width': '4%'},
                {"data": "partyName", 'sClass': "text-center",'width': '4%'},
                {"data": "mobile", 'sClass': "text-center",'width': '5%'},
                {"data": "goodsName", 'sClass': "text-center",'width': '5%'},
                {"data": "point", 'sClass': "text-center",'width': '3%'},
                {"data": "money", 'sClass': "text-center",'width': '3%'},
                {"data": "payMoney", 'sClass': "text-center",'width': '3%'},
                {"data": "amount", 'sClass': "text-center",'width': '3%'},
                {"data": "remark", 'sClass': "text-center",'width': '3%'},
				{"data": "content", 'sClass': "text-center",'width': '5%'},
                {"data": "status", 'sClass': "text-center",'width': '3%',
                    "render":function( data, type, full, meta) {
                        var str="";
                        if(data == 0){
                            str += "<span class='label label-danger' style='padding-left:10px;padding-right:10px;padding-top: inherit;'>未发放</span>";
                        }else{
                            str += "<span class='label label-success' style='padding-left:10px;padding-right:10px;padding-top: inherit;' >已发放</span> ";
                        }
                        return str;
                    }
                },
                // {"data": "createTime", 'sClass': "text-center",'width': '5%'},
                {"data": "id" , 'sClass': "text-center" ,'width':'2%',
                    "render": function (data, type, full, meta ) {
                        var str = "";
                        if(full.status == 0){
                            str += "<a href = '#' title='商品发放' onclick=editData(" + data +","+full.uid+");><i class='\glyphicon glyphicon-pencil'></i></a>&nbsp;&nbsp;&nbsp;";
                        }
                        if(full.receiver != null){
                            str += "<a href = '#' title='查看收货信息' onclick=lookInfo('"+ full.receiver +"','"+full.phone+"','"+full.address+"');><i class='\glyphicon glyphicon-eye-open'></i></a>";
                        }
                        return str;
                    }
                }
            ],

            //是否开启主题
            "bJQueryUI": true,
            "oLanguage": {    // 语言设置
                "sLengthMenu": "每页显示 _MENU_ 条记录",
                "sZeroRecords": "抱歉， 没有找到",
                "sInfo": "从 _START_ 到 _END_ /共 _TOTAL_ 条数据",
                "sInfoEmpty": "没有数据",
                "sInfoFiltered": "(从 _MAX_ 条数据中检索)",
                "sZeroRecords": "没有检索到数据",
                "sSearch": "检索:",
                "oPaginate": {
                    "sFirst": "首页",
                    "sPrevious": "前一页",
                    "sNext": "后一页",
                    "sLast": "尾页"
                }
            }
        });
    }

    //发放商品
    function editData(id,uid) {
        $("#mopTitle").text("发放商品");
        $("#id").val(id);
		$("#uid").val(uid);
        $("#editPanel").modal("toggle");//弹窗打开
    }

    //查看收货地址
    function lookInfo(receiver,phone,address) {
        $("#mopTitlelo").text("查看收货信息");
        $("#receiver").html(receiver);
        $("#phone").html(phone);
        $("#address").html(address);
        $("#receivePanel").modal("toggle");//弹窗打开
    }


    //保存
    function confirmEditConfig(){
        var id = $("#id").val();
        var content = $("#content").val();
		var uid = $("#uid").val();
        // if(content == ""){
        //     layer.msg("发放的商品信息不能为空！");
        //     return ;
        // }
        $.ajax({
            type:"POST",
            url:"/point/sendMallRecord",
            async : true,//默认就是true
            dataType:"json",
            data:{
                id : id,
				content : content,
				uid : uid
            },
            success : function(data) {
                layer.msg(data.msg, {shift: -1, time: 500}, function(){
                    location.href = "mallRecordList.html";
                });
            }
        });
    }


</script>
</body>
</html>
